package com.study.aidlsample.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 作者： zjf 10/8/20 4:23 PM
 * 描述：使用AIDL进行线程间通信,传递的数据必须实现Parcelable
 * 因为跨进程底层是通过类的序列化和反序列化进行数据传递的,
 * 并且必须在aidl包下声明一个与此数据同名且同包名的AIDL文件
 */
public class Message implements Parcelable {
    private String content;
    private String from;
    private String to;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public String toString() {
        return "Message{" +
                "content='" + content + '\'' +
                ", from='" + from + '\'' +
                ", to='" + to + '\'' +
                '}';
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.content);
        dest.writeString(this.from);
        dest.writeString(this.to);
    }

    public Message() {
    }

    protected Message(Parcel in) {
        this.content = in.readString();
        this.from = in.readString();
        this.to = in.readString();
    }

    public static final Parcelable.Creator<Message> CREATOR = new Parcelable.Creator<Message>() {
        @Override
        public Message createFromParcel(Parcel source) {
            return new Message(source);
        }

        @Override
        public Message[] newArray(int size) {
            return new Message[size];
        }
    };
}
